<!--suppress ALL -->
<div class="layui-fluid layui-anim website-anim-up" id="website-appraisal-result" lay-title="评审结果">
    <div class="layui-row website-container">
        <div class="layui-col-md10 layui-col-sm10 layui-col-xs10">
            <div class="layui-card">
                <div class="layui-card-body website-table-full">
                    <div id="resultTables">
                        <div id="resultTable-0-text"></div>
                        <div id="resultTable-0-div">
                            <table lay-filter="resultTable-0" lay-data="{id: 'resultTable-0'}"></table>
                        </div>
                        <div id="resultTable-1-text"></div>
                        <div id="resultTable-1-div">
                            <table lay-filter="resultTable-1" lay-data="{id: 'resultTable-1'}"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script data-th-inline="javascript" type="text/javascript">
    layui.use(['jquery', 'table', 'website'], function () {
        let $ = layui.jquery,
            website = layui.website,
            form = layui.form,
            table = layui.table,
            $view = $('#website-appraisal-result'),
            declareTopicId = [[${declareTopicId}]],
            tableIns;
        getPlanCounts();

        function getPlanCounts() {

            website.get(ctx + 'biz/evaluation/getAllPlanIdByDeclareTopicId/' + declareTopicId, null, function (data) {
                if (data.code === 200) {
                    const tempData = data.data;
                    $.each(tempData, function (i, item) {
                        let tableId = 'resultTable-' + i,
                            divId = tableId + '-div',
                            textId = tableId + '-text'
                        $('#' + textId).append(' <span>第 ' + (i + 1) + '次评审结果：</span>')
                        getColumn(item.planId, tableId, divId)
                        getScore(textId)
                    })
                }
            });
        }

        function getScore(textId) {
            website.get(ctx + 'client/getAppraisalResultScore/' + declareTopicId, null, function (data) {
                if (data.code === 200) {
                    $('#' + textId).append(' &nbsp;&nbsp;&nbsp;&nbsp;<span style="float: right"> 总得分：' + data.data + '</span>')
                }
            });
        }


        //获取列
        function getColumn(planId, tableId, divId) {
            let column = [
                {type: 'numbers', title: '序号',},
                {
                    title: '指标', minWidth: 100, templet: function (d) {
                        let text = d.indicatorName;
                        if (d.indicatorDescription) {
                            text += "-" + d.indicatorDescription
                        }
                        return text;
                    }
                },
                {field: 'weight', title: '权重', minWidth: 100},

            ];
            website.get(ctx + 'biz/evaluation/review/client/column/' + declareTopicId + "/" + planId, null, function (data) {
                for (expert of data.data) {
                    let item = {};
                    item.field = expert.expertId
                    item.title = expert.name
                    column.push(item);
                }
                initTable(planId, tableId, divId, column);
            });
        }

        /**
         * 初始化表格
         */
        function initTable(planId, tableId, divId, column) {
            website.table.init({
                elem: $('#' + divId).find('table'),
                id: '#' + tableId,
                limit: Number.MAX_VALUE,// 数据表格默认全部显示
                page: false,
                url: ctx + 'biz/evaluation/review/' + declareTopicId + "/" + planId,
                cols: [column],
            });
        }

    })
</script>